package com.br.aiops.schedule.judge;

import com.br.aiops.counter.AlertLogCounter;
import com.br.aiops.rule.Rule;
import com.br.aiops.schedule.AbstractSchedule;
import com.br.aiops.utils.Constants;

public class ResumeJudges {
    public static boolean isResume(AbstractSchedule schedule, AlertLogCounter alertLogCounter) {
        ResumeJudge resumeJudge = getJudge(alertLogCounter.getRule());
        return resumeJudge.isResume(schedule, alertLogCounter);
    }

    private static ResumeJudge getJudge(Rule rule) {
        if (rule.getJudgeType() == Constants.JUDGE_TYPE_DURATION) {
            return new DurationResumeJudge();
        }

        if (rule.getJudgeType() == Constants.JUDGE_TYPE_TIMES) {
            return new AlertTimesResumeJudge();
        }

        if (rule.getJudgeType() == Constants.JUDGE_TYPE_DURATION_AND_TIMES) {
            return new DurationAndAlertTimesResumeJudge();
        }

        if (rule.getJudgeType() == Constants.JUDGE_TYPE_DURATION_OR_TIMES) {
            return new DurationOrAlertTimesResumeJudge();
        }
        throw new IllegalArgumentException("rule的判断类型未知。");
    }
}
